package cn.drenal.capcap.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.drenal.capcap.common.Response;
import cn.drenal.capcap.entity.UpcomingActivity;
import cn.drenal.capcap.entity.vo.UpcomingActivityListVO;
import cn.drenal.capcap.service.UpcomingActivityService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 活动预告管理控制器
 */
@RestController
@RequestMapping("/upcoming")
@RequiredArgsConstructor
public class UpcomingActivityController {

    private final UpcomingActivityService upcomingActivityService;

    /**
     * 分页查询活动预告列表
     *
     * @param current 当前页
     * @param size    每页大小
     * @param title   预告标题
     * @param status  预告状态
     * @return 分页数据
     */
    @GetMapping("/page")
    @SaCheckPermission("homepage:upcoming:list")
    public Response<Page<UpcomingActivityListVO>> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String title,
            @RequestParam(required = false) Integer status
    ) {
        return Response.success(upcomingActivityService.page(current, size, title, status));
    }

    /**
     * 获取活动预告详情
     *
     * @param id 活动预告ID
     * @return 活动预告详情
     */
    @GetMapping("/{id}")
    @SaCheckPermission("homepage:upcoming:list")
    public Response<UpcomingActivity> getById(@PathVariable Long id) {
        return Response.success(upcomingActivityService.getById(id));
    }

    /**
     * 新增活动预告
     *
     * @param upcomingActivity 活动预告信息
     * @return 操作结果
     */
    @PostMapping
    @SaCheckPermission("homepage:upcoming:add")
    public Response<Void> add(@RequestBody UpcomingActivity upcomingActivity) {
        upcomingActivityService.save(upcomingActivity);
        return Response.success();
    }

    /**
     * 更新活动预告
     *
     * @param id               活动预告ID
     * @param upcomingActivity 活动预告信息
     * @return 操作结果
     */
    @PutMapping("/{id}")
    @SaCheckPermission("homepage:upcoming:edit")
    public Response<Void> update(@PathVariable Long id, @RequestBody UpcomingActivity upcomingActivity) {
        upcomingActivity.setId(id);
        upcomingActivityService.updateById(upcomingActivity);
        return Response.success();
    }

    /**
     * 删除活动预告
     *
     * @param id 活动预告ID
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("homepage:upcoming:delete")
    public Response<Void> delete(@PathVariable Long id) {
        upcomingActivityService.removeById(id);
        return Response.success();
    }
}